import axios from 'axios';
import qs from 'query-string';
import {
  ShortLinkInstanceView,
  ShortLinkInstanceQry,
  ShortLinkTemplateAddCmd,
  ShortLinkTemplatePageQry,
  ShortLinkTemplateView,
} from '@/types/comp/router/short-link';
import { Page } from '@/types/global-business';

export function createShortLinkTemplate(data: ShortLinkTemplateAddCmd) {
  return axios.post<ShortLinkTemplateView>('/router/short-link-template', data);
}

export function fetchShortLinkInstancePage(params: ShortLinkTemplatePageQry) {
  return axios.get<Page<ShortLinkTemplateView>>(
    '/router/short-link-template/page',
    {
      params,
      paramsSerializer: (obj) => {
        return qs.stringify(obj);
      },
    }
  );
}

export function fetchShortLinkInstance(params: ShortLinkInstanceQry) {
  return axios.get('/router/short-link-instance/one', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}
